﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace BluePrintMaster
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            ExcelDataManager.GetInstance().SetForm(this);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //初始化一个OpenFileDialog类
            OpenFileDialog fileDialog = new OpenFileDialog();
            fileDialog.Filter = "(*.xlsx)|*.xlsx";

            //判断用户是否正确的选择了文件
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                ExcelDataManager.GetInstance().OldExcelPath = fileDialog.FileName;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //初始化一个OpenFileDialog类
            OpenFileDialog fileDialog = new OpenFileDialog();
            fileDialog.Filter = "(*.xlsx)|*.xlsx";

            //判断用户是否正确的选择了文件
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                ExcelDataManager.GetInstance().NewExcelPath = fileDialog.FileName;
            }
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Exit(object sender, EventArgs e)
        {
            ExcelDataManager.GetInstance().SaveData();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            DataTable readData = ExcelDataManager.GetInstance().ReadOldExcel(7, 19, 19, 30);
            DrawContents(readData);
        }

        private void tabPage1_Click(object sender, EventArgs e)
        {

        }
        public void DrawContents(DataTable data)
        {
            dataGridView1.DataSource = data;
            //for (int row = 0; row < data.Count; row++)
            //{
            //    if (row >= dataGridView1.Rows.Count)
            //    {
            //        DataGridViewRow newRow = new DataGridViewRow();
            //        dataGridView1.Rows.Add(newRow);
            //    }
            //    List<string> currentRow = data[row];
            //    for (int column = 0; column < currentRow.Count; column++)
            //    {
            //        if (column >= dataGridView1.Columns.Count)
            //        {
            //            DataGridViewTextBoxColumn newColumn = new DataGridViewTextBoxColumn();
            //            newColumn.Name = "Column" + column;
            //            newColumn.HeaderText = "Column" + column;
            //            dataGridView1.Columns.Add(newColumn);
            //        }
            //        dataGridView1[column, row].Value = currentRow[column];
            //    }
            //}
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}
